IF EXISTS (SELECT * FROM sysobjects WHERE name = 'GenConnectionString' AND type IN ('FN','IF','TF'))
     DROP FUNCTION dbo.GenConnectionString
GO

CREATE FUNCTION dbo.GenConnectionString
     ( @TrustedFlag       tinyint,
       @ServerName        varchar(128),
       @DatabaseName      varchar(128),
       @UserName          varchar(128),
       @Password          varchar(128),
       @OLEDBProviderName varchar(128),
       @SuppressPWFlag    tinyint )
RETURNS varchar(512)
AS
/*
 *
 * GenConnectionString
 *
 * Purpose:      
 *
 * Inputs:       
 *
 * Assumes:      
 *
 * Effects:      
 *
 * Returns:      
 *
 * Calling
 * Application:  
 *
 * Note(s):      
 *
 * CfgCtrl Keys: 
 *
 * Author(s):    NOVA Concepts Ltd.
 *
 * Change Log:   Initial Release, 06/09/2009, 1.00.0000
 *
 */
BEGIN
     DECLARE @ReturnValue varchar(512)

     SELECT @ReturnValue = 'Data Source='
                         + @ServerName
                         + ';Initial Catalog='
                         + @DatabaseName 
                         + ';Provider='
                         + @OLEDBProviderName
                         + ';Auto Translate=False;'
                         + CASE WHEN @TrustedFlag = 1 
                                THEN 'Integrated Security=SSPI;'
                                ELSE 'User ID='
                                   + @UserName
                                   + CASE WHEN @SuppressPWFlag = 1
                                          THEN ';'
                                          ELSE ';Password='
                                             + @Password
                                             + ';'
                                     END
                           END

     RETURN @ReturnValue
END
GO
